package authoritah.ui.member;

import java.awt.BorderLayout;

import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;

import authoritah.db.Member;


public class MemberMainView extends JPanel {
	private MemberMainModel model;
	
	private JTable memberList;
	private JScrollPane memberListScroll;

	private JToolBar toolBar;
	
	private JButton addMember;
	private JButton removeMember;
	private JButton editMember;
	
	public MemberMainView(MemberMainModel model) {
		super();
		this.model = model;
		
		initComponents();
		layoutComponents();
	}
	
	private void initComponents() {
		memberList = new JTable(model);
		memberListScroll = new JScrollPane(memberList);
		
		toolBar = new JToolBar();
		
		addMember = new JButton();		
		removeMember = new JButton();
		editMember = new JButton();
	}
	
	private void layoutComponents() {		
		toolBar.add(addMember);
		toolBar.add(editMember);
		toolBar.add(removeMember);
		toolBar.setOrientation(JToolBar.VERTICAL);
		
		this.setLayout(new BorderLayout());
		this.add(toolBar, BorderLayout.WEST);
		this.add(memberListScroll, BorderLayout.CENTER);
	}
	
	public void setIcons() {
		addMember.setIcon(new ImageIcon("res/book_add.png"));
		removeMember.setIcon(new ImageIcon("res/book_delete.png"));
		editMember.setIcon(new ImageIcon("res/book_edit.png"));
	}
	
	public void setAddAction(Action action){
		addMember.setAction(action);
	}
	
	public void setRemoveAction(Action action){
		removeMember.setAction(action);
	}
	
	public void setEditAction(Action action){
		editMember.setAction(action);
	}

	public Member getSelectedMember() {
		return model.getMember(memberList.getSelectedRow());
	}
}
